<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');


class Application extends CI_Controller {

    var $titlePage = "";
    var $meteKey = "";
    var $home;

    public function __construct() {
        parent::__construct();


        //load model
        $this->load->model('danhmucsp');
        $this->load->model('product_model');
        $this->load->model('user_model');
        $this->load->model('pay_model');
        $this->load->model('order_model');
        $this->load->model('menu_model');
        $this->load->model('captcha_model');
        $this->load->model('com_model');
        $this->load->model('cf_model');

        //load library
        $this->load->library('cart');
        $this->load->library('form_validation');
        $this->load->library('pagination');
        $this->load->library('Breadcrumb');
        //load helper
        $this->load->helper('form');
        $this->load->helper('captcha');
        $this->load->helper('recaptchalib');
        $this->load->helper('float');

        $this->titlePage = false;
        $this->meteKey = false;
        $this->home = '<img src="' . base_url() . 'images/icon_home.png" width="14" height="14"/>';

        if (isset($_SERVER['HTTP_REFERER'])) {
            $this->session->set_userdata('previous_page', $_SERVER['HTTP_REFERER']);
        } else {
            $this->session->set_userdata('previous_page', base_url());
        }
    }

    public function render($content) {
        $data['header'] = $this->header();
        $data['search'] = $this->search();
        $data['login'] = $this->login();
        $data['giohang'] = $this->giohang();
        
        $data['dichvu'] = $this->dichvu();
        $data['hotro'] = $this->hotro();
        $data['content'] = $content;
        $data["footer"] = $this->footer();

        $data['titlePage'] = $this->titlePage;
        $data['metaKey'] = $this->meteKey;

        $this->load->view("template", $data);
    }
    
    public function header() {
        $data = array();
        $data["m_menu"] = $this->menu_model->getMenu()->result();
        $data["s_menu"] = $this->danhmucsp->selectAll()->result();
        return $this->load->view('header', $data, true);
    }

    public function search() {
        $data['pname'] = $this->product_model->GetCategory(NULL)->result();
        return $this->load->view('search', $data, true);
    }

    public function login() {
        $data = array();
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
            return $this->load->view('thongtin_user', $data,TRUE);
        }else
            return $this->load->view('login', $data, true);
    }

    public function giohang() {
        $data = array();
        return $this->load->view('giohang_view', $data, true);
    }

    public function menu_left() {
        $data['menu_left'] = $this->danhmucsp->selectAll(array('PStatus' => 1))->result();
        return $this->load->view('menu_left', $data, true);
    }

    public function dichvu() {
        $data = array();

        return $this->load->view('dichvu', $data, true);
    }

    public function hotro() {
        $data = array();
        return $this->load->view('hotrotructuyen', $data, true);
    }
    
    public function footer(){
        $data = array();
        return $this->load->view("footer_view",$data,TRUE);
    }
    
    public function cfPag() {
        $config['full_tag_open'] = '<span class="pag">';
        $config['full_tag_close'] = '</span>';
        $config['num_tag_open'] = '<span class="pag_num">';
        $config['num_tag_close'] = '</span>';
        $config['first_link'] = 'Trước';
        $config['last_link'] = 'Sau';
        $config['cur_tag_open'] = '<span class="tag_cur">';
        $config['cur_tag_close'] = '</span>';
        $config['next_tag_open'] = '<span class="tag_next">';
        $config['next_tag_close'] = '</span>';
        $config['prev_tag_open'] = '<span class="tag_pre">';
        $config['prev_tag_close'] = '</span>';
        $config['uri_segment'] = 3;

        $this->pagination->initialize($config);
    }
}

?>
